import  re

html = '''
<!doctype html>
<html>

	<head>
		<title>《率土之滨》武将库_武将系统介绍_《率土之滨》手游官网</title></title>
	    <title>《率土之滨》技能库_技能系统介绍_《率土之滨》手游官网</title></title>
		<meta name="keywords" content="率土之滨,率土之滨手游,率土之滨官网,率土之滨游戏,率土之滨网站,网易率土之滨,率土之滨网易,率土之滨官方游戏,率土之滨游戏官方,手游率土之滨,游戏率土之滨,率土之滨礼包,率土之滨下载,率土之滨安卓,率土之滨iOS,率土之滨苹果,率土之滨福利，率土之滨助手，网易手游">
		<meta name="description" content="《率土之滨》手游官网，《率土之滨》武将系统详细介绍，武将各方面属性作用解析，武将组合及战法详解。">
		<meta charset="utf-8">
		<meta name="renderer" content="webkit">
		<link rel="dns-prefetch" href="https://nie.res.netease.com">
		
		<meta name="author" content="网易，NetEase Inc.">
		<meta name="copyright" content="网易，NetEase Inc.">
		<meta name="pmid" content="">
		<meta name="editor" content="">
		<meta name="designer" content="">
		<meta name="front-end technicist" content="">
		<meta name="applicable-device" content="pc">
		<link rel="alternate" media="only screen and(max-width: 640px)" href="/m/card_list.html">
		

		<script type="text/javascript">!function(){function o(o,e){var t=new RegExp("(?:&|/?)"+e+"=([^&$]+)").exec(o);return t?t[1]:""}1==/iphone|android|ipod/i.test(navigator.userAgent.toLowerCase())&&"mobile"!=o(location.search,"from")&&(location.href="//stzb.163.com/m/card_list.html")}();</script>
		
		<!--[if lt IE 9]>
    <script src="https://nie.res.netease.com/comm/html5/html5shiv.js"></script>
    <![endif]-->

		
		<link type="text/css" rel="stylesheet" href="https://stzb.res.netease.com/pc/gw/20230821163204/pkg/card_list_e5ac4d9.css">


	</head>

	<body>




		

	
	<div id="share_title" pub-name="分享标题">
	网易《率土之滨》，谋略热爱者的游戏</div>
	<div id="share_url" pub-name="分享地址"></div>
	<img id="share_pic" src="https://stzb.res.netease.com/pc/gw/20230821163204/img/share_3c507db.jpg" pub-name="分享图片">
	<div id="share_desc" pub-name="分享内容">沙盘战略，寸土必争！这个世界资源有限，争夺无处不在，是乱世永恒，还是天下一统？这是一场人与人创造的乱世风云史！</div>
</div>

	
	</body>

</html>



'''

# search 查询第一个
# findall 查询多个
# re.S 换行查询
# ? 指的是非贪婪查询，非常规的信息不会打印；比如两个紧邻的title结尾
# title = re.search(r'<title>(.*)</title>', html).group(1)
# print(title)
# title1 = re.search(r'<title>(.*?)</title>', html).group(1)
# print(title1)
# title2 = re.findall(r'<title>(.*?)</title>', html)
# print(title2)
# div = re.search(r'<div[^>]*id="share_title"[^>]*>(.*?)</div>', html, re.S)
# if div:
#     print(div.group(1).strip())









# match/fullmatch/sub/subn/split/finditer
text = """Hello 2025-10-28  \n 我的电话：13800138000 或 13900139000
邮箱：tom+tag@site.com  Jerry@example.com.cn
空白行下一行是TAB\t结束"""

# m = re.match(r'\w{5}\s+\d{4}',text) # 5个单词 1个空格 4个数字
# print(m)
# m1 = re.match(r'\w{5}\s+\d{4}\W\d{2}\W\d{2}',text)
# print(m1)
# m2 = re.fullmatch(r'\d+','1380013800') # fullmatch 要求全段匹配
# print(bool(m2))
# m21 = re.fullmatch(r'\d+','13900a139000')
# print(bool(m21))
# m3 =  re.sub(r'(\d{3})\d{4}(\d{4})', r'\1****\2', text) # \1 代表第 1 个捕获组（前 3 位）\2 代表第 2 个捕获组（后 4 位）
# print(m3)
# new_txt, n = re.subn(r'\s+', ' ', text)
# print('subn 次数=', n, '结果首60字符=', new_txt[:60])
# print(re.split(r'\d+-', 'a-1-b-2-c')) # \d+- \d+ → 连续 1 个或多个数字;-紧跟一个减号;(a-1)-(b-2)-(c)
# 扫描整个字符串，每找到一次匹配就返回一个 Match 对象迭代器，不会一次性占内存
# for m in re.finditer(r'[\w.+]+@\w+(?:\.\w+)+', text):
#     print('  邮箱:', m.group())


# re.A/re.M/re.I
# pattern = r'^hello\s+(\d+)'
# print('I+M 旗标:', re.findall(pattern, 'hello 123\nHello 456', re.I | re.M))

# /w  /W /d /D /s /S
demo = '9A_\t8'
print(r'  \w  =>', re.findall(r'\w', demo))    # 单词字符
print(r'  \W  =>', re.findall(r'\W', demo))    # 非单词字符
print(r'  \d  =>', re.findall(r'\d', demo))    # 数字
print(r'  \D  =>', re.findall(r'\D', demo))    # 非数字
print(r'  \s  =>', repr(re.findall(r'\s', demo)))  # 空白
print(r'  \S  =>', repr(re.findall(r'\S', demo)))  # 非空白



